package com.chixing.ih.module.programmer.mapper.provider;

import com.chixing.ih.module.programmer.pojo.PersonalSkill;
import com.chixing.ih.util.EmptyUtil;
import org.apache.ibatis.jdbc.SQL;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘岩
 * Date: 2020-09-29
 * Time: 16:55
 *
 * @version 1.0
 */
public class PersonalSkillMapperProvider {

    public String insertOne() {
        return new SQL() {{
            INSERT_INTO("tbl_personal_skill");
            VALUES("skill_name", "#{skillName}");
            VALUES("create_time", "#{createTime}");
        }}.toString();
    }


    public String deleteOneById() {
        return new SQL() {{
            UPDATE("tbl_user_skill");
            SET("is_deleted=1");
            WHERE("user_skill_id=#{id}");
        }}.toString();
    }


    public String updateOne(PersonalSkill personalSkill) {
        return new SQL() {{
            UPDATE("tbl_personal_skill");
            if (!EmptyUtil.isEmpty(personalSkill.getSkillName())) {
                SET("skill_name=#{skillName}");
            }
            if (!EmptyUtil.isEmpty(personalSkill.getSkillScore())) {
                SET("skill_score=#{skillScore}");
            }
            WHERE("id=#{id}");
        }}.toString();

    }
//23,119,123
    public String listAll() {
        return new SQL() {{
            SELECT("*");
            FROM("tbl_personal_skill");
            WHERE("id=#{user_skill_id}");
        }}.toString();
    }

    public String getSkillId() {
        return new SQL() {{
            SELECT("user_skill_id");
            FROM("tbl_user_skill");
            WHERE("user_id=#{userId} AND is_deleted=0");
        }}.toString();
    }



    public String insert() {
        return new SQL() {{
            INSERT_INTO("tbl_user_skill");
            VALUES("user_id", "#{userId}");
            VALUES("user_skill_id", "#{userSkillId}");
        }}.toString();
    }

    public String getSkillName() {
        return new SQL() {{
            SELECT("s.skill_name");
            FROM("tbl_user_skill us join tbl_personal_skill s on us.user_skill_id=s.id");
            WHERE("us.user_id=#{userId}");
        }}.toString();
    }




}
